package com.nononsenseapps.feeder.ui.feed

import android.view.View
import android.widget.TextView
import com.github.florent37.expansionpanel.ExpansionLayout
import com.nononsenseapps.feeder.ui.R
import com.nononsenseapps.feeder.util.PREF_VAL_OPEN_WITH_WEBVIEW

class FeedItemHolder_Expandable(view: View, actionCallback: ActionCallback,viewModel:Boolean) :
           FeedItemHolder_Mini(view,actionCallback,viewModel) {

    private val  expansionLayout: ExpansionLayout = view.findViewById(R.id.expansionLayout)
    private val  contentView: TextView = view.findViewById(R.id.content_text)
    private val  container: View = view.findViewById(R.id.container)
    init {
        contentView.setOnClickListener {
            /*val context = view.context
            if (context != null) {
                actionCallback.onItemClick(rssItem!!)
                openItemToView(PREF_VAL_OPEN_WITH_WEBVIEW,context)
            }*/
            super.onClick(it)
        }
        //contentView.setOnCreateContextMenuListener(this)
        contentView.setOnLongClickListener {
            val context = view.context
            if (context != null) {
                actionCallback.onItemClick(rssItem!!)
                openItemToView(PREF_VAL_OPEN_WITH_WEBVIEW,context)
            }
            true
        }
        if(!viewModel)
           container.setOnCreateContextMenuListener(this)
    }

    override fun initContextMenu(){

    }

    override fun resetView() {
        super.resetView()
        expansionLayout.collapse(false)
    }

    override fun onClick(view: View) {
        if(!expansionLayout.isExpanded)
            expansionLayout.expand(true)
        else
           super.onClick(view)
    }

    override fun fillTitle(forceRead: Boolean) {
        super.fillTitle(forceRead)
        rssItem?.let { rssItem ->
            contentView.text = rssItem.plainSnippet
        }
    }
}